<?php

# 
# Copyright (c) 2002-2007 Eric Wallengren
# This file is part of the Continuous Automated Build and Integration 
# Environment (CABIE)
# 
# CABIE is distributed under the terms of the GNU General Public
# License version 2 or any later version.  See the file COPYING for copying 
# permission or http://www.gnu.org. 
#                                                                            
# THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED OR  
# IMPLIED, without even the implied warranty of MERCHANTABILITY or FITNESS 
# FOR A PARTICULAR PURPOSE.  ANY USE IS AT YOUR OWN RISK. 
#                                                                            
# Permission to modify the code and to distribute modified code is granted, 
# provided the above notices are retained, and a notice that the code was 
# modified is included with the above copyright notice. 
# 

    require_once("auth.php");
    require_once("unixsys.php");
    require_once("defs.php");
    require_once("dbdefs.php");
    require_once("cmddefs.php");
    require_once("menuperms.php");
    require_once("common.php");

    _displayheader($randomimages);

?>

<?php 

    require_once('xmlrpc.inc');

    $SQL   = new sqlfuncs();
    $CMD   = new cmddefs();

    $SQL->__construct($server, $username, $password, $database);

    $sqlarray = _getactiveservers($SQL, 1);

    $servername = $_REQUEST['server'];

    _displayactiveservers($sqlarray, $servername); 

    $port = serverport($SQL, $_REQUEST['server']);

    $_REQUEST['port'] = $port;

    $CMD->__construct($_REQUEST);

    $command = $_REQUEST['cmd'];

    $cmdarray = $CMD->_returnusercmd($_REQUEST['cmd']);

    _servermenu($SQL, $_REQUEST['server']);

    $user = $_SESSION['PHP_AUTH_USER'];

    if ($cmdarray['level'] > 0) {
        if (isset($user)) {
            $ok = _verifylevel($SQL, $user, $cmdarray['level']);
        } else {
            $ok = 0;
        }
    } else {
        $ok = 1;
    }

    if (!isset($cmdarray['func'])) {

        $isup = _serverup($SQL, $_REQUEST['server']);
        
        if ($isup) {

            if ($_REQUEST['user']) {

                $targetid = $_REQUEST['jobname']."_id";
                $class = _getrunningclass($SQL, $_REQUEST['server'], 
                                          $_REQUEST['jobname']);
                _jobmenu($SQL, $_REQUEST['server'], 
                         $_REQUEST['jobname'], $class, 8);
        
            }

            if ($ok) {
                processrequest($_REQUEST, $_REQUEST['cmd'], $CMD, $cmdarray, 0);
            } else {
                echo "<td class=jobname>Access to $command denied</td>\n".
                     "</tbody>\n".
                     "</table>\n";
            }

        } else {
            displaymessage($_REQUEST['server'], "server unavailable");
        }

    } else {

        if ($ok) {
            $func = $cmdarray['func'];
            $func($SQL, $cmdarray);
        } else {
            echo "<td class=jobname>Access to $command denied</td>\n".
                 "</tbody>\n".
                 "</table>\n";
        }

    }

    echo "</div>\n";

    if (isset($_REQUEST['recs'])) {
        $toshow = $_REQUEST['recs'];
    } else {
        $toshow = 10;
    }

    echo "<br>\n".
         "<form action=\"#\">\n".
         "<legend>expanded builds</legend>\n".
         "<input type='text' id='toshow' maxlength=4 size=4 value=$toshow />\n".
         "</form>\n";

?>

<?php
    #$mem = memory_get_usage();
    #$usage = sprintf("%d", $mem/1024);
    #echo "<p>memory used: ".$usage."k</p>\n";
?>

</body>
</html>

<?
    exit;
?>
    
